Skip to content

Add State v2 guard and DI integration demos to State sample#14

Merged
Skymly merged 1 commit into
mainfrom
feature/state-v2-sample
Jun 22, 2026
Merged

Add State v2 guard and DI integration demos to State sample#14
Skymly merged 1 commit into
mainfrom
feature/state-v2-sample

Conversation

@Skymly

@Skymly Skymly commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extends DesignPatterns.Samples.State to demonstrate State v2 features:
    • Guard delegates: [Transition] Guard property with CanCancelDraft / CanCancelSubmitted static guard methods on the holder class
    • DI integration: generated RegisterDi method + AddTransitionTable extension, resolving ITransitionTable<OrderStatus, OrderTrigger> from ServiceProvider
    • GetAllowedTriggers: shows allowed triggers per state and terminal state (Paid has none)
  • Adds Cancelled state and Cancel trigger for richer edge coverage
  • Changes DesignPatternsSampleKind from Core to DependencyInjection to pull in DI extension and enable DesignPatterns_EnableDiIntegration

Sample output

=== Manual TransitionTableBuilder (with guard) ===
  Draft + Submit -> Submitted
  Submitted + Pay -> Paid
  Draft + Cancel -> Cancelled
  Paid + Pay is invalid (expected).

=== Generated [StateMachine] table (with guard) ===
Initial state: Draft
  Draft + Submit -> Submitted
  Submitted + Pay -> Paid
  Draft + Cancel -> Cancelled
  Submitted + Cancel -> Cancelled
  Paid + Pay is invalid (expected).

=== DI integration (RegisterDi + AddTransitionTable) ===
Resolved from DI: OrderStatusTransitionTable
DI table initial state: Draft
  Draft + Submit -> Submitted
  Submitted + Pay -> Paid
  Cancelled + Submit is invalid (expected).

=== GetAllowedTriggers ===
Allowed triggers from Draft: Submit, Cancel
Allowed triggers from Submitted: Pay, Cancel
Allowed triggers from Paid (terminal): (none — terminal state)

Test plan

  • dotnet build DesignPatterns.Samples.State -c Release — 0 warnings, 0 errors
  • dotnet run --project DesignPatterns.Samples.State -c Release — output matches expected

Extends the State sample to demonstrate v2 features:
- Guard delegates on [Transition] with CanCancelDraft/CanCancelSubmitted
  static guard methods on the holder class
- DI integration via generated RegisterDi + AddTransitionTable extension
- GetAllowedTriggers output showing terminal state (Paid)
- Cancelled state added to enum for richer edge coverage
- DesignPatternsSampleKind changed from Core to DependencyInjection to
  pull in the DI extension and enable DesignPatterns_EnableDiIntegration
@Skymly
Skymly merged commit c0af032 into main Jun 22, 2026
1 check passed
@Skymly
Skymly deleted the feature/state-v2-sample branch June 22, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant